using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using engine.frmModel;

namespace engine
{
    public partial class frmMain : DevComponents.DotNetBar.Metro.MetroForm,IEngineImportFact
    {
        Engine engine;
        public frmMain()
        {
            InitializeComponent();
            engine = new Engine();
            engine.setOnEngineImportFact(this);
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmWriter frm = new frmWriter();
            //frm.Show();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            Fact goal = new Fact("Loi khuyen");
            engine.backTracking(goal);
            this.lbResult.Text = String.Format("[{0}] : {1}", goal.Key, goal.value.ToString());
        }

        Fact IEngineImportFact.getFactbyUser(Fact goal)
        {
            goal.value = new tdhString(goal);
            while(true)
            {
                goal.value.frm.ShowDialog();
                if (goal.value.frm.DialogResult == DialogResult.OK)
                {
                    goal.value.frm.Close();
                    return goal;
                }
                else if (goal.value.frm.DialogResult == DialogResult.Cancel)
                {
                    goal.value.frm.Close();
                    return null;
                }
            }
            return null;
        }

        private void mnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}